package com.sigmatrix.h5.web.controller.utils;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.sigmatrix.h5.entity.v2.DisDealer;
import com.sigmatrix.h5.entity.v2.DisTerminalShop;
import com.sigmatrix.h5.service.db.DisDealerDBService;
import com.sigmatrix.h5.service.db.DisTerminalShopDBService;
import com.sigmatrix.h5.web.BaseController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;



@Api(tags={"经销商/门店测试"})
@RestController
@RequestMapping("/util/test/agency")
public class TestAgencyController extends BaseController{
	
	@Autowired
	private DisTerminalShopDBService disTerminalShopDBService;
	
	@Autowired
	private DisDealerDBService disDealerDBService;
	
	@ApiOperation("分页查询门店列表")
	@GetMapping("/shop/page/size/{size}/current/{current}/esecode/{esecode}")
	public Page<DisTerminalShop> selectShopPage(@PathVariable String esecode,@PathVariable int size,@PathVariable int current) {
		DisTerminalShop shop = new DisTerminalShop();
		shop.setTablePrefix("_"+esecode);
		return disTerminalShopDBService.selectPage(new Page<DisTerminalShop>(current, size), new EntityWrapper<>(shop));
	}
	
	@ApiOperation("分页查询经销商列表")
	@GetMapping("/dealer/page/size/{size}/current/{current}/esecode/{esecode}")
	public Page<DisDealer> selectDealerPage(@PathVariable String esecode,@PathVariable int size,@PathVariable int current) {
		DisDealer dealer = new DisDealer();
		dealer.setTablePrefix("_"+esecode);
		return disDealerDBService.selectPage(new Page<DisDealer>(current, size), new EntityWrapper<>(dealer));
	}
	
	
	@ApiOperation("分页查询门店列表(by名称)")
    @GetMapping("/shop/page/size/{size}/current/{current}/name/{name}/esecode/{esecode}")
     public Page<DisTerminalShop> selectShopPage(@PathVariable String esecode,@PathVariable int size,@PathVariable int current,@PathVariable String name) {
            DisTerminalShop shop = new DisTerminalShop();
            if(StringUtils.isNotEmpty(name)){
                    shop.setName(name);
            }
             shop.setTablePrefix("_"+esecode);
                 return disTerminalShopDBService.selectPage(new Page<DisTerminalShop>(current, size), new EntityWrapper<>(shop));
         }
  
    @ApiOperation("分页查询经销商列表(by名称)")
    @GetMapping("/dealer/page/size/{size}/current/{current}/name/{name}/esecode/{esecode}")
    public Page<DisDealer> selectDealerPage(@PathVariable String esecode,@PathVariable int size,@PathVariable int current,@PathVariable String name) {
             DisDealer dealer = new DisDealer();
             if(StringUtils.isNotEmpty(name)){
                     dealer.setName(name);
             }
            dealer.setTablePrefix("_"+esecode);
             return disDealerDBService.selectPage(new Page<DisDealer>(current, size), new EntityWrapper<>(dealer));
     }

	
}
